package com.example.demo.control;

import com.example.demo.model.Result;
import com.example.demo.model.Student;
import com.example.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class StudentController {
    @Autowired
    private StudentService studentService;
    @PostMapping("/api/addStudent")
    public String add(@RequestParam("name") String name,@RequestParam("studentNumber") String studentNumber,@RequestParam("gender") String gender,@RequestParam("age") int age,@RequestParam("className") String className){
        Result result = new Result();
        Student student = new Student();
        student.setStudentNumber(studentNumber);
        student.setAge(age);
        student.setGender(gender);
        student.setName(name);
        student.setClassName(className);

        studentService.add(student);

        result.setSuccess(true);
        result.setCode("200");
        result.setMessage("添加学生信息成功");
        return "index";
    }
}
